﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AudioDemo.View
{
    /// <summary>
    /// media2.xaml 的交互逻辑
    /// </summary>
    public partial class media2 : Window
    {
        public ProgressConverter prgConverter = null;
        public media2()
        {
            InitializeComponent();
            prgConverter = new ProgressConverter();
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            if (button.Content.ToString() == "播放")
            {
                button.Content = "暂停";
                mediaElement.Play();
            }
            else
            {
                button.Content = "播放";
                mediaElement.Pause();
            }
        }
        //视频资源打开
        private void mediaElement_MediaOpened(object sender, RoutedEventArgs e)
        {
            //设置媒体的长度
            //sliderPosition.Maximum = mediaElement.NaturalDuration.TimeSpan.TotalSeconds;
        }
    }

    public class ProgressConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return ((TimeSpan)value).TotalSeconds;
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return TimeSpan.FromSeconds((double)value);
        }
    }
}
